

 class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }

  //二叉树的层平均值
class Solution {
    public int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        int left=minDepth(root.left)+1;
        int right=minDepth(root.right)+1;
        if(left==1&&right!=1){
            return right;
        }else if(right==1&&left!=1){
            return left;
        }
        return Math.min(left,right);
    }
}

//二叉树的最小深度
class Solution1 {
    public int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        int left=minDepth(root.left)+1;
        int right=minDepth(root.right)+1;
        if(left==1&&right!=1){
            return right;
        }else if(right==1&&left!=1){
            return left;
        }
        return Math.min(left,right);
    }
}